<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @sendUserSearch="getSearch"
      :searchData="userSearchData"
      :isHaveExport="false"
      :isHaveAdd="false"
    >
      <template v-slot:headRight>
        <div class="fx head-right-icon">
          <p @click="refreshBtn">
            <i class="el-icon-refresh"></i>&nbsp;&nbsp;更新
          </p>
        </div>
      </template>
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list.data"
          stripe
          v-loading="loading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
        >
          <el-table-column label="LOGO" min-width="100">
            <template slot-scope="scope">
              <el-popover placement="right" title trigger="hover">
                <img :src="scope.row.logo_big" style="width: 300px" />
                <img
                  slot="reference"
                  :src="scope.row.logo_big"
                  :alt="scope.row.logo_big"
                  style="width: 80px"
                />
              </el-popover>
            </template>
          </el-table-column>

          <el-table-column label="名称" min-width="140">
            <template slot-scope="scope">
              {{ scope.row.title || "----" }}
            </template>
          </el-table-column>

          <el-table-column label="类型" min-width="80">
            <template slot-scope="scope">
              {{
                scope.row.types == 1
                  ? "中石油"
                  : scope.row.types == 2
                  ? "中石化"
                  : scope.row.types == 3
                  ? "壳牌"
                  : "其他"
              }}
            </template>
          </el-table-column>

          <el-table-column label="其他信息" min-width="160">
            <template slot-scope="scope">
              <p><b>编号：</b>{{ scope.row.gasid || "----" }}</p>
              <p>
                <b>地址：</b>
                {{
                  scope.row.province +
                  scope.row.city +
                  scope.row.area +
                  scope.row.address
                }}
              </p>
              <p>
                <b>是否能开发票：</b>
                {{ scope.row.is_invoice == 1 ? "能开" : "不能开" }}
              </p>
            </template>
          </el-table-column>

          <el-table-column label="操作" min-width="100">
            <template slot-scope="scope">
              <el-button
                :loading="$store.state.isLoading"
                type="primary"
                size="mini"
                @click="showPrice(scope.row)"
              >
                价格列表
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog
      :close-on-click-modal="false"
      title="价格列表"
      :modal-append-to-body="false"
      :visible.sync="show_price"
      width="800px"
    >
      <el-table
        :data="price_lists"
        stripe
        header-row-class-name="head_color"
        tooltip-effect="dark"
        style="width: 99.8%"
      >
        <el-table-column label="名称" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.title || "----" }}
          </template>
        </el-table-column>

        <el-table-column label="编码" min-width="80">
          <template slot-scope="scope">
            {{ scope.row.oil_id || "----" }}
          </template>
        </el-table-column>

        <el-table-column label="类别" min-width="60">
          <template slot-scope="scope">
            {{
              scope.row.types == 1
                ? "汽油"
                : scope.row.types == 2
                ? "柴油"
                : scope.row.types == 3
                ? "天然气"
                : "----"
            }}
          </template>
        </el-table-column>

        <el-table-column label="价格" min-width="160">
          <template slot-scope="scope">
            <p>
              <b>车服服务价格：</b>
              {{ scope.row.service_price | keepTwoNum }}
            </p>
            <p>
              <b>国标价：</b>
              {{ scope.row.standard_price | keepTwoNum }}
            </p>
            <p>
              <b>枪价：</b>
              {{ scope.row.gun_price | keepTwoNum }}
            </p>
          </template>
        </el-table-column>

        <el-table-column label="枪号" min-width="100">
          <template slot-scope="scope">
            {{ scope.row.gun_no }}
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import { gasStationSearchData } from "@/assets/js/searchData/searchData"; //引入搜索的数据
export default {
  data() {
    return {
      userSearchData: gasStationSearchData,
      loading: false,
      list: [],
      pageSize: 10,
      currentPage: 1,
      searchAll: {},

      price_lists: [],
      show_price: false,
    };
  },
  components: {},
  created() {
    this.getNewsAll();
  },
  methods: {
    refreshBtn() {
      this.$api.getStation.gas_station_refresh(this.form).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess({ text: "更新成功" });
          this.getNewsAll();
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result);
        }
      });
    },
    showPrice(val) {
      this.price_lists = val.price_lists || [];
      this.show_price = true;
    },
    getSearch(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;

      this.$api.getStation.gas_station_lists(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },
  },
};
</script>

<style lang="less" scoped>
</style>
